package org.bsplus.service;

import java.util.Date;
import org.bsplus.dao.IssueDAO;
import org.bsplus.domain.Issue;
import java.util.List;
import javax.annotation.Resource;
import org.bsplus.domain.IssueSeverity;
import org.bsplus.domain.IssueStatus;
import org.bsplus.domain.IssueType;
import org.bsplus.domain.User;
import org.bsplus.util.pagination.PageLoadRequest;
import org.bsplus.util.pagination.ResultPage;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

@Transactional
public class IssueService
{
    private IssueDAO issueDAO;

    @Resource
    @Required
    public void setIssueDAO(IssueDAO issueDAO)
    {
        this.issueDAO = issueDAO;
    }
    
    public void createIssue(Issue issue)
    {
        Assert.notNull(issue);

        issue.setCreated(new Date());
        issue.setCreatedBy(User.getCurrentUser());
        issue.setIssueStatus(IssueStatus.OPEN);

        issueDAO.saveOrUpdateIssue(issue);
    }

    public List<Issue> getAllIssues()
    {
        return issueDAO.getAllIssues();
    }

    public List<IssueType> getAllIssueTypes()
    {
        return issueDAO.getAllIssueTypes();
    }

    public List<IssueSeverity> getAllIssueSeverities()
    {
        return issueDAO.getAllIssueSeverities();
    }

    public ResultPage<Issue> getIssues(PageLoadRequest pageLoadRequest)
    {
        return issueDAO.getIssues(pageLoadRequest);
    }
}
